'use strict';

const jshint = require('./jshint');
const buildJS = require('./webpack');
const clean = require('./clean');
const styl2css = require('./styl2css');
const livereload = require('./livereload');
const watcher = require('glob-watcher');
const server = require('./server');
const jade2js = require('./jade2js');
const gutil = require('gulp-util');

//预编译css
clean(['public/css/*']);

//打包js
clean(['public/tpls/*'], function() {
    jade2js('app/client/tpls/**/*.jade', 'public/tpls', function() {
        //webpack打包
        buildJS.dev(['app/client/js/*/*.js'], 'public/js', function() {
            //js代码检查
            jshint(['app/client/js/**/*.js']);
            watcher(['app/client/js/**/*.js']).on('change', function (path) {
                jshint(path);
            });
            watcher(['app/client/tpls/**/*.jade']).on('change', function (p) {
                jade2js(p, path.normalize(path.dirname(p).replace(/client(\\|\/)views(\\|\/)/, 'public/')));
            });
        });
    });
});

//livereload
livereload();

//启动服务
server();